package order_service

import (
	"bee/pkg/logging"
	"github.com/go-resty/resty/v2"
	"github.com/tidwall/gjson"
	"time"
)

type CC struct {
	FullName             string `json:"fullName"`
	LocationCode         string `json:"locationCode"`
	BizLocationCode      string `json:"bizLocationCode"`
	Nsrsbh               string `json:"nsrsbh"`
	Shxydm               string `json:"shxydm"`
	InternalUsableStatus string `json:"internalUsableStatus"`
	Source               string `json:"source"`
}

func (o Order) CreateCustomer(host string) (customerId string, err error) {

	c := CC{
		FullName:             o.FullName,
		LocationCode:         "130982",
		BizLocationCode:      "130000",
		Nsrsbh:               "",
		Shxydm:               "",
		InternalUsableStatus: "Y",
		Source:               "214649602167",
	}

	url := host + "/cc-production/test/company/saveOrUpdateAgency"

	headers := make(map[string]string)
	headers["Content-Type"] = "application/json"
	headers["appId"] = "20010100010000"
	headers["timestamp"] = "1467791956367"
	headers["appKey"] = "48778FFD44ADE08A462BF1EF3085BBD2D02613EF"

	client := resty.New()

	customerResp, ccErr := client.R().SetHeaders(headers).SetBody(c).Post(url)
	if ccErr != nil {
		logging.ZapLogger.Infow("【创建客户】", "错误信息", ccErr, "traceId", o.TraceId)
		return "", ccErr
	}

	// 测试环境服务并发会挂
	time.Sleep(1 * time.Second)

	customerId = gjson.Get(customerResp.String(), "data").String()
	logging.ZapLogger.Infow("【创建客户】", "customerId", customerId, "traceId", o.TraceId)

	return customerId, nil

}